//
//  QYXTopRankingTableViewCell.m
//  OpenYourEyes
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 Google AdWords. All rights reserved.
//

#import "QYXTopRankingTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation QYXTopRankingTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
       
        
        self.topRankingImage = [[UIImageView alloc] init];
        self.topRankingImage.userInteractionEnabled = YES;
        UILongPressGestureRecognizer *topLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
        
        [self.topRankingImage addGestureRecognizer:topLongPressGesture];
        [self.contentView addSubview:_topRankingImage];
        
        self.topRankingView = [[UIView alloc] init];
        self.topRankingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
      
        [self.topRankingImage addSubview:_topRankingView];
        
        
        self.topRankingLabel = [[UILabel alloc] init];
        self.topRankingLabel.textAlignment = 1;
        self.topRankingLabel.font = [UIFont fontWithName:@"FZLTZCHJW--GB1-0" size:17];
        self.topRankingLabel.textColor = [UIColor whiteColor];
        [self.topRankingImage addSubview:_topRankingLabel];
        
        self.topCategoryLabel = [[UILabel alloc] init];
        self.topCategoryLabel.textAlignment = 2;
        self.topCategoryLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        self.topCategoryLabel.textColor = [UIColor whiteColor];
        [self.topRankingImage addSubview:_topCategoryLabel];
        
        
        self.topDurationLabel = [[UILabel alloc] init];
        self.topDurationLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        self.topDurationLabel.textColor = [UIColor whiteColor];
        [self.topRankingImage addSubview:_topDurationLabel];
        
        
        self.topAngularLabel = [[UILabel alloc] init];
        self.topAngularLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:15];
        self.topAngularLabel.textAlignment = 1;
        self.topAngularLabel.textColor = [UIColor whiteColor];
        [self.topRankingImage addSubview:_topAngularLabel];
        
        
        self.topRankingNum = [[UILabel alloc] init];
        self.topRankingNum.font = [UIFont fontWithName:@"Lobster 1.4" size:17];
        self.topRankingNum.textColor = [UIColor whiteColor];
        self.topRankingNum.textAlignment = 1;
        [self.topRankingImage addSubview:_topRankingNum];
        
 
   
    }
    

    return self;
 
    
}



- (void)longTap:(UILongPressGestureRecognizer *)sender
{
    self.topRankingLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.topCategoryLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.topDurationLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.topAngularLabel.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
    self.topRankingNum.textColor = [UIColor colorWithWhite:1.000 alpha:0.000];
   
    self.topRankingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    if (sender.state == UIGestureRecognizerStateEnded) {
        
        self.topRankingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
      
        self.topRankingLabel.textColor = [UIColor whiteColor];
        self.topCategoryLabel.textColor = [UIColor whiteColor];
        self.topDurationLabel.textColor = [UIColor whiteColor];
        self.topAngularLabel.textColor = [UIColor whiteColor];
        self.topRankingNum.textColor = [UIColor whiteColor];
 
    }
    
}



- (void)layoutSubviews

{
    [super layoutSubviews];
    
    self.topRankingImage.frame = self.bounds;
    
    self.topRankingView.frame = self.topRankingImage.bounds;
    
    self.topRankingLabel.frame = CGRectMake(0, self.topRankingView.bounds.size.height / 3, kScreenWidth, self.topRankingView.bounds.size.height / 6);
    
    self.topCategoryLabel.frame = CGRectMake(0, self.topRankingView.bounds.size.height / 3 + self.topRankingLabel.bounds.size.height, kScreenWidth / 2, self.topRankingLabel.bounds.size.height);
    
    
    self.topDurationLabel.frame = CGRectMake(self.topCategoryLabel.bounds.size.width, self.topCategoryLabel.frame.origin.y, self.topCategoryLabel.bounds.size.width, self.topCategoryLabel.bounds.size.height);
    
    self.topAngularLabel.frame = CGRectMake(kScreenWidth / 3 * 2, 0, kScreenWidth / 3, kScreenHeight / 9);
    
    self.topRankingNum.frame = CGRectMake(0, self.topDurationLabel.bounds.size.height + self.topRankingImage.bounds.size.height / 3, kScreenWidth, kScreenHeight / 3 / 2);
    
    
}




- (void)setTopRankingModel:(QYXTopRankingModel *)topRankingModel

{
    if (_topRankingModel != topRankingModel) {
        _topRankingModel = topRankingModel;
        
        [self.topRankingImage sd_setImageWithURL:[NSURL URLWithString:topRankingModel.coverModel.detail] placeholderImage:kPlaceHolderImage completed:nil];
        
        self.topRankingLabel.text = topRankingModel.title;
        
        self.topCategoryLabel.text = [NSString stringWithFormat:@"#%@  /", topRankingModel.category];
        
        self.topDurationLabel.text = [NSString stringWithFormat:@"  %d%ld' %ld''", 0,topRankingModel.duration /60, topRankingModel.duration % 60];
            
        self.topAngularLabel.text = [topRankingModel.label objectForKey:@"text"];
        
        
    }

    
}


- (void)setRankingNumber:(NSInteger)rankingNumber

{
    _rankingNumber = rankingNumber;
    
   self.topRankingNum.text = [NSString stringWithFormat:@"%ld", self.rankingNumber];
    
    
}




@end
